// import { onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
// import { getAppConfig } from '@/api/index';
// import { shareUtils } from '@/utils/share'
import  {useSettingStore} from '@/store/setting'
// export default async function share() {

//     try {
//         const page = getCurrentPages().pop()
//         const key = 'appconfig';
//         let config = null
//         let { $page } = page

//         if (uni.getStorageSync(key)) {
//             config = JSON.parse(uni.getStorageSync(key));
//         } else {
//             config = await getAppConfig()
//             uni.setStorageSync(key, JSON.stringify(config))
//         }
//         let path: string = $page.fullPath
       
//         path = shareUtils.buildPathQuery($page.fullPath)

//         onShareAppMessage(() => {

//             return {
//                 title: config.name,
//                 path: path,
//             }
//         })

//         onShareTimeline(() => {

//             return {
//                 title: config.name,
//                 query: path
//             }
//         })
//     } catch (e) {
//         console.error(e)
//         onShareAppMessage(() => {

//             return {
//                 title: '会一美装板',
//                 path: page.route,
//             }
//         })

//         onShareTimeline(() => {

//             return {
//                 title: '会一美装板',
//                 query: page.route,
//             }
//         })
//     }

//     return {
//         onShareAppMessage,
//         onShareTimeline
//     }
// }
export default function useShare(){
    const getShareCover = (path,share_title,share_cover)=>{
        return useSettingStore().initSettingListByStore().then(res=>{
       
             
            let index_path = '/pages/index/index';
             let c1 = res.pages_share_cover_map[index_path]?.share_cover_url;
             let c2 = res.pages_share_cover_map[`/${path}`]?.share_cover_url;

             let t1 = res.pages_share_cover_map[index_path]?.share_title;
             let t2 = res.pages_share_cover_map[`/${path}`]?.share_title;

             let title = t2&& t2!='' ? t2:t1;
             let imageUrl = c2&& c2!='' ? c2:c1

             if(share_title && share_title !=''){
                title = share_title
             }

             if(share_cover && share_cover !=''){
                imageUrl = share_cover
             }
            //  debugger

             return {
                title,
                imageUrl
             }
     
         })
     }

     return {getShareCover}
}
